package com.apes.fn.rpt.profit.grossProfitProcess.processor;

import com.apes.fn.rpt.profit.grossProfitProcess.CommonGrossProfitProcess;
import com.apes.fn.rpt.profit.grossProfitProcess.GrossProfitProcess;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 车险佣金
 */
@Component
public class InsuranceCommissionExpense extends CommonGrossProfitProcess implements GrossProfitProcess {

    @Override
    public String getSQL(Date taskDate){

        return " SELECT X.CREATE_DATE, " +
                "       '保险' " +
                "                                                                                                 INCOME_CATEGORIES, " +
                "       '车险佣金'                                                                                    SERVE_TYPE_NAME, " +
                "       X.DEPT_ID, " +
                "       X.COMPANY_ID, " +
                "       SUM(X.FN_COMMISSION)                                                                      AMOUNT, " +
                "       0                                                                                         TIMES, " +
                "       SUM(X.FN_COMMISSION)                                                                      PRICE_TOTAL, " +
                "       0                                                                                         COST, " +
                "       0                                                                                         CONSUMABLE_USE, " +
                "       0                                                                                         ACCESSORY_COST, " +
                "       0                                  vip_in, " +
                "       0                                  vip_out, " +
                "       0                                                                                         MAN_HOUR_COST, " +
                "       SUM(X.PLATFORM_MANAGEMENT_FEE)                                                            PLATFORM_MANAGEMENT_FEE, " +
                "       0                                                                                         SUPPLY_CHAIN_MANAGEMENT_FEE" +
                " FROM (SELECT TRUNC(A.CREATE_DATE) CREATE_DATE, A.DEPT_ID, A.COMPANY_ID, B.FN_COMMISSION, B.PLATFORM_MANAGEMENT_FEE " +
                "      FROM POLICY_INFORMATION A, " +
                "           POLICY_INFORMATION_ITEM B " +
                "      WHERE A.ID = B.POLICY_INFORMATION_ID " +
                "        AND A.CREATE_DATE >= to_date(:P_DATE, 'YYYY-mm-dd') " +
                "        AND A.CREATE_DATE < to_date(:P_DATE, 'YYYY-mm-dd') " +
                "          + 1) X " +
                " GROUP BY X.CREATE_DATE, X.DEPT_ID, X.COMPANY_ID";
    }

    @Override
    public boolean support(String type) {
        return "InsuranceCommission".equals(type);
    }
}
